package com.ruoyi.web.controller.sbgl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sbgl.domain.TbSbglSjcj;
import com.ruoyi.sbgl.service.ITbSbglSjcjService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 水表数据采集Controller
 *
 * @author ruoyi
 * @date 2023-11-16
 */
@RestController
@RequestMapping("/sbgl/sjcj")
public class TbSbglSjcjController extends BaseController
{
    @Autowired
    private ITbSbglSjcjService tbSbglSjcjService;

    /**
     * 查询水表数据采集列表
     */
    @PreAuthorize("@ss.hasPermi('sbgl:sjcj:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbSbglSjcj tbSbglSjcj)
    {   System.out.println(tbSbglSjcj);

        List<TbSbglSjcj> list = tbSbglSjcjService.selectTbSbglSjcjList(tbSbglSjcj);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('sbgl:sjcj:list')")
    @GetMapping("/caiji")
    public TableDataInfo listcaiji(TbSbglSjcj tbSbglSjcj)
    {

        startPage();
        List<TbSbglSjcj> list = tbSbglSjcjService.selectTbSbglSjcjListcaji(tbSbglSjcj);
        return getDataTable(list);
    }


    /**
     * 导出水表数据采集列表
     */
    @PreAuthorize("@ss.hasPermi('sbgl:sjcj:export')")
    @Log(title = "水表数据采集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbSbglSjcj tbSbglSjcj)
    {
        List<TbSbglSjcj> list = tbSbglSjcjService.selectTbSbglSjcjList(tbSbglSjcj);
        ExcelUtil<TbSbglSjcj> util = new ExcelUtil<TbSbglSjcj>(TbSbglSjcj.class);
        util.exportExcel(response, list, "水表数据采集数据");
    }

    /**
     * 获取水表数据采集详细信息
     */
    @PreAuthorize("@ss.hasPermi('sbgl:sjcj:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbSbglSjcjService.selectTbSbglSjcjById(id));
    }

    /**
     * 新增水表数据采集
     */
    @PreAuthorize("@ss.hasPermi('sbgl:sjcj:add')")
    @Log(title = "水表数据采集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbSbglSjcj tbSbglSjcj)
    {
        return toAjax(tbSbglSjcjService.insertTbSbglSjcj(tbSbglSjcj));
    }

    /**
     * 修改水表数据采集
     */
    @PreAuthorize("@ss.hasPermi('sbgl:sjcj:edit')")
    @Log(title = "水表数据采集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbSbglSjcj tbSbglSjcj)
    {
        System.out.println(tbSbglSjcj);
        if(tbSbglSjcj.getFmzt()==1)
        {//关阀门
            return toAjax(tbSbglSjcjService.updateTbSbglSjcj(tbSbglSjcj));
        }
        else//开阀门
            return toAjax(tbSbglSjcjService.updateTbSbglSjcj1(tbSbglSjcj));

    }

    /**
     * 删除水表数据采集
     */
    @PreAuthorize("@ss.hasPermi('sbgl:sjcj:remove')")
    @Log(title = "水表数据采集", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbSbglSjcjService.deleteTbSbglSjcjByIds(ids));
    }

    /**
     * 获取总用水量
     */
    @GetMapping("/watersum")
    public double listcaiji()
    {
        double sum= tbSbglSjcjService.selectTbSbglSjcjListwatersum();
        return sum;
    }
}
